﻿using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevSamPle.FormPlugin
{
    [Description("【表单插件】读取Common.config配置文件"), HotUpdate]
    public class ReadCommonConfig : AbstractDynamicFormPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.EqualsIgnoreCase("ReaCommon"))
            {
                Read();
                //Read2();
            }
        }

        private void Read2()
        {
            var dll = new Uri(typeof(KDConfiguration).Assembly.CodeBase).LocalPath;
            var sitedir = Directory.GetParent(Path.GetDirectoryName(dll)).FullName;
            var path = Path.Combine(sitedir, @"App_Data\Common.config");
            var file = new ExeConfigurationFileMap() { ExeConfigFilename = path };
            var configurationManager = ConfigurationManager.OpenMappedExeConfiguration(file, ConfigurationUserLevel.None);
            var managementSiteUrl = configurationManager.AppSettings.Settings["managementSiteUrl"].Value;
            var isManagementSite = configurationManager.AppSettings.Settings["isManagementSite"].Value;
            var MaxPageRow = configurationManager.AppSettings.Settings["MaxPageRow"].Value;
            var msg = string.Format("managementSiteUrl：{0}\r\nisManagementSite：{1}\r\nMaxPageRow：{2}"
                , managementSiteUrl
                , isManagementSite
                , MaxPageRow);
            this.View.ShowMessage(msg);
        }

        private void Read()
        {
            var managementSiteUrl = KDConfiguration.Current.GetAppSettingItemValue("managementSiteUrl");
            var isManagementSite = KDConfiguration.Current.GetAppSettingItemValue("isManagementSite");
            var MaxPageRow = KDConfiguration.Current.GetAppSettingItemValue("MaxPageRow");
            var msg = string.Format("managementSiteUrl：{0}\r\nisManagementSite：{1}\r\nMaxPageRow：{2}"
                , managementSiteUrl
                , isManagementSite
                , MaxPageRow);
            this.View.ShowMessage(msg);
        }
    }
}
